package view.swing.popup;

import java.awt.Component;
import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

import model.iview.IPlayer;
import model.iview.ScoreComparator;
import util.Resources;
public class EndGameWindow {

	private List<IPlayer> players;
	private Component parentWindow;
	
	private EndGameWindow(Component parentWindow) {
	    this.parentWindow = parentWindow;
	}

	public EndGameWindow(Component parentWindow, List<IPlayer> list) {
		this(parentWindow);
		this.players = list;
	}

	public void showWindow() {
		StringBuffer sb = new StringBuffer();
		sb.append(Resources.getString("Game.End"));
		sb.append("\n\n");
		sb.append(Resources.getString("Game.Ranking"));
		sb.append("\n");
		Collections.sort(players, new ScoreComparator());
		for (int i = 0; i < players.size(); i++) {
			sb.append(Resources.getString("Game.RankingLine", (i + 1), players.get(i).getName(), players.get(i).getScore()));
			sb.append("\n");
		}
		JOptionPane.showMessageDialog(parentWindow, sb.toString(), "Partie terminée",
				JOptionPane.INFORMATION_MESSAGE);
	}
}
